package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.BrandService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.BrandBo;
import com.ddwl.schema.bo.goods.BrandSearchBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.BrandVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Fu Zhaohui
 * @version 1.0.0
 * @date 2019/8/8 13:59
 */
@Api(tags = "品牌管理")
@RequestMapping("brand")
@RestController
public class BrandController extends BaseController {

    @Autowired
    private BrandService brandService;

    @PostMapping("page")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("分页查询品牌")
    public RestVo<PageVo<BrandVo>> page(@Valid @RequestBody PageBo<BrandSearchBo> pageBo) {
        return RestVo.ok(brandService.page(pageBo));
    }

    @PostMapping("index")
    @Auth
    @ApiOperation("分页查询品牌")
    public RestVo<List<BrandVo>> index(@Valid @RequestBody PageBo<BrandSearchBo> pageBo) {
        return RestVo.ok(brandService.index(pageBo));
    }

    @PostMapping("/create")
    @Auth
    @ApiOperation("创建品牌")
    public RestVo<String> create(@Valid @RequestBody BrandBo bo) {
        return RestVo.ok(brandService.create(bo));
    }

    @PostMapping("/update")
    @Auth
    @ApiOperation("创建品牌")
    public RestVo update(@Valid @RequestBody BrandBo bo) {
        brandService.update(bo);
        return RestVo.ok();
    }

    @DeleteMapping("del")
    @Auth
    @ApiOperation("删除品牌")
    public RestVo delete(@RequestParam String id) {
        brandService.delete(id);
        return RestVo.ok();
    }

    @GetMapping("/detail")
    @Auth
    @ApiOperation("条码搜索品牌")
    public RestVo<BrandVo> detail(@ApiParam(value = "品牌ID", required = true) @RequestParam String id) {
        return RestVo.ok(brandService.detail(id, getUserId()));
    }
}
